﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Net.Mail;
using System.Configuration;
using System.Web.UI.WebControls;

public class Common
{

    //this class probably needs to be extended
    //to allow for attachments and other such things.
    //have fun jr. :)
	public class Email
    {
        public static void Send(string from, string to, string subject, string body, MailPriority priority)
        {
            MailMessage mail = new MailMessage(from, to, subject, body);
            mail.Priority = priority;

            //leave the smtpclient constructor empty
            //that way it pulls the configuration 
            //settings from the web.config
            SmtpClient client = new SmtpClient();
            client.Send(mail);
        }
    }

    public static class DefaultValues
    {
        /// <summary>
        /// South Carolina
        /// </summary>        
        public const string State = "South Carolina";

        /// <summary>
        /// USA
        /// </summary>
        public const string CountryAbbreviation = "USA";

        /// <summary>
        /// Business
        /// </summary>
        public const string AddressType = "Business";

        /// <summary>
        /// Business
        /// </summary>
        public const string PhoneType = "Business";

        /// <summary>
        /// Business
        /// </summary>
        public const string EmailType = "Business";
    }

    public class Utility
    {   
        /// <summary>
        /// Binds a gridview to a list of data. 
        /// </summary>
        /// <typeparam name="T">The type of object.</typeparam>
        /// <param name="gridView">The girdview to bind too.</param>
        /// <param name="data">The list of type T to bind.</param>
        public static void BindGridView<T>(GridView gridView, List<T> data)
        {
            gridView.DataSource = data;
            gridView.DataBind();
        }

        /// <summary>
        /// Binds drop down list to a list of data. DataTextField and DataValueField are defaulted to "DESCRIPTION" and "ID" respectively.
        /// </summary>
        /// <typeparam name="T">The type of object.</typeparam>
        /// <param name="dropDownList">The drop down list to bind too.</param>
        /// <param name="data">The list of type T to bind.</param>
        public static void BindDropDownList<T>(DropDownList dropDownList, List<T> data)
        {
            BindDropDownList<T>(dropDownList, data, "DESCRIPTION", "ID");
        }

        /// <summary>
        /// Binds drop down list to a list of data. DataTextField and DataValueField are defaulted to "DESCRIPTION" and "ID" respectively.
        /// </summary>
        /// <typeparam name="T">The type of object.</typeparam>
        /// <param name="dropDownList">The drop down list to bind too.</param>
        /// <param name="data">The list of type T to bind.</param>\
        /// <param name="defaultText">The default text to display.</param>
        public static void BindDropDownList<T>(DropDownList dropDownList, List<T> data, string defaultText)
        {
            BindDropDownList<T>(dropDownList, data, defaultText, "DESCRIPTION", "ID");
        }

        /// <summary>
        /// Binds drop down list to a list of data. 
        /// </summary>
        /// <typeparam name="T">The type of object.</typeparam>
        /// <param name="dropDownList">The drop down list to bind too.</param>
        /// <param name="data">The list of type T to bind.</param>
        /// <param name="dataTextField">The property name on the T object to use as the data text field property of the drop down list.</param>
        /// <param name="dataValueField">The property name on the T object to use as the data value field property of the drop down list.</param>
        public static void BindDropDownList<T>(DropDownList dropDownList, List<T> data, string dataTextField, string dataValueField)
        {
            BindDropDownList<T>(dropDownList, data, string.Empty, dataTextField, dataValueField);
        }

        /// <summary>
        /// Binds drop down list to a list of data. 
        /// </summary>
        /// <typeparam name="T">The type of object.</typeparam>
        /// <param name="dropDownList">The drop down list to bind too.</param>
        /// <param name="data">The list of type T to bind.</param>
        /// <param name="defaultText">The default text to display.</param>
        /// <param name="dataTextField">The property name on the T object to use as the data text field property of the drop down list.</param>
        /// <param name="dataValueField">The property name on the T object to use as the data value field property of the drop down list.</param>
        public static void BindDropDownList<T>(DropDownList dropDownList, List<T> data, string defaultText, string dataTextField, string dataValueField)
        {
            dropDownList.DataSource = data;            
            dropDownList.DataTextField = dataTextField;
            dropDownList.DataValueField = dataValueField;
            dropDownList.DataBind();

            ListItem item = dropDownList.Items.FindByText(defaultText);

            if (null != item)
            {
                dropDownList.SelectedValue = item.Value;
            }
        }
    }
}